package com.example.cp.busi;

import androidx.lifecycle.Observer;
import androidx.recyclerview.widget.StaggeredGridLayoutManager;

import com.example.cp.R;
import com.example.cp.adapter.BannerAdapter;
import com.example.cp.adapter.VideoAdapter;
import com.example.cp.databinding.ActivityVideoBinding;
import com.example.cp.entivity.BannerResult;
import com.example.cp.entivity.VideoResult;
import com.example.cp.mvvm.base.BaseActivity;

import java.util.ArrayList;
import java.util.List;

public class VideoActivity extends BaseActivity<ActivityVideoBinding,VideoViewModel> {
    List<VideoResult.DataBean> list = new ArrayList<>();
    private VideoAdapter adapter;
    private BannerAdapter bannerAdapter;
    List<BannerResult.DataBean> data = new ArrayList<>();
    @Override
    public void initView() {

        adapter = new VideoAdapter(R.layout.item_video,list);
        binding.rv.setAdapter(adapter);
        binding.rv.setLayoutManager(new StaggeredGridLayoutManager(2,StaggeredGridLayoutManager.VERTICAL));
        viewModel.getVideo(2,15);
        viewModel.success.observe(this, new Observer<VideoResult>() {
            @Override
            public void onChanged(VideoResult videoResult) {
                if (videoResult.getCode() == 200){
                    list.addAll(videoResult.getData());
                    adapter.notifyDataSetChanged();
                }
            }
        });
        bannerAdapter = new BannerAdapter(data);
        binding.banner.setAdapter(bannerAdapter);
        viewModel.getBanner();
        viewModel.bannerSuccess.observe(this, new Observer<BannerResult>() {
            @Override
            public void onChanged(BannerResult bannerResult) {
                if (bannerResult.getCode() == 200){
                    data.addAll(bannerResult.getData());
                    bannerAdapter.notifyDataSetChanged();
                }
            }
        });


    }

    @Override
    public void initData() {

    }

    @Override
    public int bindLoutId() {
        return R.layout.activity_video;
    }

    @Override
    public Class<VideoViewModel> getViewModel() {
        return VideoViewModel.class;
    }


}
